// pages/address-modify/address-modify.js
import post from '../../util/post'
Page({
    /**
     * 页面的初始数据
     */
    data: {
        id:'',
        consignee:'',
        phone:'',
        address:'',
        detailedaddress:''
    },
    getinput(e){
        console.log(e)
        if(e.currentTarget.id == 1){
            this.setData({
                consignee:e.detail.value
            })
            return
        }
        if(e.currentTarget.id == 2){
            this.setData({
                phone:e.detail.value
            })
            return
        }
        if(e.currentTarget.id == 3){
            this.setData({
                address:e.detail.value
            })
            return
        }
        if(e.currentTarget.id == 4){
            this.setData({
                detailedaddress:e.detail.value
            })
            return
        }
    },
    judgen(){
        if(!this.data.consignee||(/^[0-9]/).test(this.data.consignee)){
            wx.showToast({
              title: '收货人不正确',
              icon:'none'
            })
            return
        }
        if((/^1[3456789]\d{9}$/).test(this.data.phone)){
            wx.showToast({
                title: '电话号码不正确',
                icon:'none'
              })
              return
        }
        if(!this.data.address){
            wx.showToast({
                title: '地址不能为空',
                icon:'none'
              })
              return
        }
        if(!this.data.detailedaddress){
            wx.showToast({
                title: '详细地址不能为空',
                icon:'none'
              })
              return
        }
    },
    async preservation(){
        let address = {}
        address.id = this.data.id
        address.consignee = this.data.consignee
        address.phone = this.data.phone
        address.address = this.data.address
        address.detailedaddress = this.data.detailedaddress
        await post('wx/addressmodify',address).then(res=>{
            console.log(res)
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
        id:options.id,
        consignee:options.consignee,
        phone:options.phone,
        address:options.address,
        detailedaddress:options.detailedaddress
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})